﻿#region Copyright (c) 11/25/2011, Olaf Kober <amarok.projects@gmail.com>
//================================================================================
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.
//================================================================================
#endregion

#if TESTS

using System;
using System.Globalization;
using System.Windows.Controls;
using NUnit.Framework;


namespace Amarok.Presentation
{
	[TestFixture]
	public class Test_ValidatingViewModel
	{
		private class MyViewModel : ValidatingViewModel
		{
			public String Text
			{
				get
				{
					return "BLAH";
				}
				set
				{
					base.RaisePropertyChanged(() => Text);
				}
			}

			public Int32 Number
			{
				get
				{
					return 0;
				}
				set
				{
					base.RaisePropertyChanged(() => Number);
				}
			}
		}

		private class MyValidationRule : ValidationRule
		{
			public override ValidationResult Validate(Object value, CultureInfo cultureInfo)
			{
				if ((Int32)value < 0)
					return new ValidationResult(false, "ERROR");
				else
					return new ValidationResult(true, null);
			}
		}

		private class MyTypedValidationRule : ValidationRule<Int32>
		{
			protected override ValidationResult OnValidate(Int32 value, CultureInfo cultureInfo)
			{
				if (value < 0)
					return base.Failure("ERROR");
				else
					return base.Success();
			}
		}


		// --- TESTS ---


		[Test]
		public void Test_Error()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.Error, Is.EqualTo(""));

			viewModel.SetError("Text", "ERROR");
			Assert.That(viewModel.Error, Is.EqualTo(""));

			viewModel.SetObjectError("ERROR{0}", 123);
			Assert.That(viewModel.Error, Is.EqualTo("ERROR123"));

			viewModel.ClearError("Text");
			Assert.That(viewModel.Error, Is.EqualTo("ERROR123"));

			viewModel.ClearObjectError();
			Assert.That(viewModel.Error, Is.EqualTo(""));
		}

		[Test]
		public void Test_Indexer()
		{
			var viewModel = new MyViewModel();

			Assert.That(viewModel[null], Is.EqualTo(""));
			Assert.That(viewModel[""], Is.EqualTo(""));
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel["NotExisting"], Is.EqualTo(""));

			viewModel.SetObjectError("BLAH");

			Assert.That(viewModel[null], Is.EqualTo(""));
			Assert.That(viewModel[""], Is.EqualTo(""));
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel["NotExisting"], Is.EqualTo(""));

			viewModel.SetError("Text", "ERROR{0}", 123);

			Assert.That(viewModel[null], Is.EqualTo(""));
			Assert.That(viewModel[""], Is.EqualTo(""));
			Assert.That(viewModel["Text"], Is.EqualTo("ERROR123"));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel["NotExisting"], Is.EqualTo(""));

			viewModel.SetError("Number", "VALUE");

			Assert.That(viewModel[null], Is.EqualTo(""));
			Assert.That(viewModel[""], Is.EqualTo(""));
			Assert.That(viewModel["Text"], Is.EqualTo("ERROR123"));
			Assert.That(viewModel["Number"], Is.EqualTo("VALUE"));
			Assert.That(viewModel["NotExisting"], Is.EqualTo(""));

			viewModel.ClearErrors();

			Assert.That(viewModel[null], Is.EqualTo(""));
			Assert.That(viewModel[""], Is.EqualTo(""));
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel["NotExisting"], Is.EqualTo(""));
		}

		[Test]
		public void Test_HasErrors()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.HasErrors, Is.False);

			viewModel.SetObjectError("ERROR");
			Assert.That(viewModel.HasErrors, Is.True);

			viewModel.ClearObjectError();
			Assert.That(viewModel.HasErrors, Is.False);

			viewModel.SetError("Text", "ERROR");
			Assert.That(viewModel.HasErrors, Is.True);

			viewModel.ClearErrors();
			Assert.That(viewModel.HasErrors, Is.False);
		}

		[Test]
		public void Test_HasError_Expression()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.HasError(() => viewModel.Text), Is.False);

			viewModel.SetObjectError("ERROR");
			Assert.That(viewModel.HasError(() => viewModel.Text), Is.False);

			viewModel.SetError("Number", "ERROR");
			Assert.That(viewModel.HasError(() => viewModel.Text), Is.False);

			viewModel.SetError("Text", "ERROR");
			Assert.That(viewModel.HasError(() => viewModel.Text), Is.True);

			viewModel.ClearErrors();
			Assert.That(viewModel.HasError(() => viewModel.Text), Is.False);
		}

		[Test]
		public void Test_HasError_PropertyName()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.HasError("Text"), Is.False);

			viewModel.SetObjectError("ERROR");
			Assert.That(viewModel.HasError("Text"), Is.False);

			viewModel.SetError("Number", "ERROR");
			Assert.That(viewModel.HasError("Text"), Is.False);

			viewModel.SetError("Text", "ERROR");
			Assert.That(viewModel.HasError("Text"), Is.True);

			viewModel.ClearErrors();
			Assert.That(viewModel.HasError("Text"), Is.False);
		}

		[Test]
		public void Test_SetObjectError()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.Error, Is.EqualTo(""));
			Assert.That(viewModel.HasErrors, Is.False);

			viewModel.BeginRecording();
			viewModel.SetObjectError("ERROR");
			Assert.That(viewModel.Error, Is.EqualTo("ERROR"));
			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Error;HasErrors"));

			viewModel.BeginRecording();
			viewModel.SetObjectError("ERROR{0}", 123);
			Assert.That(viewModel.Error, Is.EqualTo("ERROR123"));
			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Error;HasErrors"));

			viewModel.BeginRecording();
			viewModel.SetObjectError("");
			Assert.That(viewModel.Error, Is.EqualTo(""));
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Error;HasErrors"));
		}

		[Test]
		public void Test_SetObjectError_Null()
		{
			var viewModel = new MyViewModel();

			Assert.Throws<ArgumentNullException>(() =>
				{
					viewModel.SetObjectError(null);
				});
		}

		[Test]
		public void Test_SetError_Expression()
		{
			var viewModel = new MyViewModel();

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));

			viewModel.BeginRecording();
			viewModel.SetError(() => viewModel.Text, "MESSAGE{0}", 123);

			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.HasError("Text"), Is.True);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo("MESSAGE123"));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Text;HasErrors"));

			viewModel.BeginRecording();
			viewModel.SetError(() => viewModel.Text, "");

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Text;HasErrors"));

			viewModel.BeginRecording();
			viewModel.SetError(() => viewModel.Text, "");

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_SetError_Expression_NullMessage()
		{
			var viewModel = new MyViewModel();

			Assert.Throws<ArgumentNullException>(() =>
				{
					viewModel.SetError(() => viewModel.Text, null);
				});
		}

		[Test]
		public void Test_SetError_PropertyName()
		{
			var viewModel = new MyViewModel();

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));

			viewModel.BeginRecording();
			viewModel.SetError("Text", "MESSAGE{0}", 123);

			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.HasError("Text"), Is.True);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo("MESSAGE123"));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Text;HasErrors"));

			viewModel.BeginRecording();
			viewModel.SetError("Text", "");

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Text;HasErrors"));

			viewModel.BeginRecording();
			viewModel.SetError("Text", "");

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_SetError_PropertyName_NullMessage()
		{
			var viewModel = new MyViewModel();

			Assert.Throws<ArgumentNullException>(() =>
				{
					viewModel.SetError("Text", null);
				});
		}

		[Test]
		public void Test_SetError_PropertyName_NotExisting()
		{
			var viewModel = new MyViewModel();

			Assert.Throws<ArgumentException>(() =>
				{
					viewModel.SetError("NotExistingProperty", "MESSAGE{0}", 123);
				});
		}

		[Test]
		public void Test_ClearObjectError()
		{
			var viewModel = new MyViewModel();
			viewModel.SetObjectError("ERROR");

			Assert.That(viewModel.Error, Is.EqualTo("ERROR"));
			Assert.That(viewModel.HasErrors, Is.True);

			viewModel.BeginRecording();
			viewModel.ClearObjectError();

			Assert.That(viewModel.Error, Is.EqualTo(""));
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Error;HasErrors"));

			viewModel.BeginRecording();
			viewModel.ClearObjectError();
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_ClearErrors_NoErrors()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.HasErrors, Is.False);

			viewModel.BeginRecording();
			viewModel.ClearErrors();

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_ClearErrors_ObjectError()
		{
			var viewModel = new MyViewModel();
			viewModel.SetObjectError("ERROR");

			viewModel.BeginRecording();
			viewModel.ClearErrors();

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Error;HasErrors"));

			viewModel.BeginRecording();
			viewModel.ClearErrors();
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_ClearErrors_PropertyError()
		{
			var viewModel = new MyViewModel();
			viewModel.SetError("Text", "ERROR");

			viewModel.BeginRecording();
			viewModel.ClearErrors();

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Text;HasErrors"));

			viewModel.BeginRecording();
			viewModel.ClearErrors();
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_ClearError_Expression_NoErrors()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.HasErrors, Is.False);

			viewModel.BeginRecording();
			viewModel.ClearError(() => viewModel.Text);

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_ClearError_Expression()
		{
			var viewModel = new MyViewModel();
			viewModel.SetError("Text", "TEXT{0}", 123);
			viewModel.SetError("Number", "NUMBER{0}", 123);

			Assert.That(viewModel.HasErrors, Is.True);

			viewModel.BeginRecording();
			viewModel.ClearError(() => viewModel.Number);

			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel["Text"], Is.EqualTo("TEXT123"));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			viewModel.ClearError(() => viewModel.Text);

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Text;HasErrors"));

			viewModel.BeginRecording();
			viewModel.ClearErrors();
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_ClearError_PropertyName_NoErrors()
		{
			var viewModel = new MyViewModel();
			Assert.That(viewModel.HasErrors, Is.False);

			viewModel.BeginRecording();
			viewModel.ClearError("Text");

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_ClearError_PropertyName()
		{
			var viewModel = new MyViewModel();
			viewModel.SetError("Text", "TEXT{0}", 123);
			viewModel.SetError("Number", "NUMBER{0}", 123);

			Assert.That(viewModel.HasErrors, Is.True);

			viewModel.BeginRecording();
			viewModel.ClearError("Number");

			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel["Text"], Is.EqualTo("TEXT123"));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			viewModel.ClearError("Text");

			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Text;HasErrors"));

			viewModel.BeginRecording();
			viewModel.ClearErrors();
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_Validate_Expression_ValidationRule()
		{
			var viewModel = new MyViewModel();

			viewModel.BeginRecording();
			var result = viewModel.Validate(new MyValidationRule(), 123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyValidationRule(), -123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.False);
			Assert.That(result.ErrorContent, Is.EqualTo("ERROR"));
			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.True);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo("ERROR"));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyValidationRule(), 123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyValidationRule(), 123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_Validate_PropertyName_ValidationRule()
		{
			var viewModel = new MyViewModel();

			viewModel.BeginRecording();
			var result = viewModel.Validate(new MyValidationRule(), 123, "Number");

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyValidationRule(), -123, "Number");

			Assert.That(result.IsValid, Is.False);
			Assert.That(result.ErrorContent, Is.EqualTo("ERROR"));
			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.True);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo("ERROR"));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyValidationRule(), 123, "Number");

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyValidationRule(), 123, "Number");

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_Validate_Expression_TypedValidationRule()
		{
			var viewModel = new MyViewModel();

			viewModel.BeginRecording();
			var result = viewModel.Validate(new MyTypedValidationRule(), 123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyTypedValidationRule(), -123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.False);
			Assert.That(result.ErrorContent, Is.EqualTo("ERROR"));
			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.True);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo("ERROR"));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyTypedValidationRule(), 123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyTypedValidationRule(), 123, () => viewModel.Number);

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

		[Test]
		public void Test_Validate_PropertyName_TypedValidationRule()
		{
			var viewModel = new MyViewModel();

			viewModel.BeginRecording();
			var result = viewModel.Validate(new MyTypedValidationRule(), 123, "Number");

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyTypedValidationRule(), -123, "Number");

			Assert.That(result.IsValid, Is.False);
			Assert.That(result.ErrorContent, Is.EqualTo("ERROR"));
			Assert.That(viewModel.HasErrors, Is.True);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.True);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo("ERROR"));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyTypedValidationRule(), 123, "Number");

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo("Number;HasErrors"));

			viewModel.BeginRecording();
			result = viewModel.Validate(new MyTypedValidationRule(), 123, "Number");

			Assert.That(result.IsValid, Is.True);
			Assert.That(result.ErrorContent, Is.Null);
			Assert.That(viewModel.HasErrors, Is.False);
			Assert.That(viewModel.HasError("Text"), Is.False);
			Assert.That(viewModel.HasError("Number"), Is.False);
			Assert.That(viewModel["Text"], Is.EqualTo(""));
			Assert.That(viewModel["Number"], Is.EqualTo(""));
			Assert.That(viewModel.GetRecording().AsString(";"), Is.EqualTo(""));
		}

	}
}

#endif
